#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,l,v,ans1,ans2;
int dc[100005];
int vc[100005];
int ac[100005];
int p[100005];
int car[100005][2];
bool f[100005];
void check(int x)
{
    if(ac[x]==0&&vc[x]<=v)
    {
        car[x][0]=-1;
        car[x][0]=-1;
        return ;
    }
    if(ac[x]==0&&vc[x]>v)
    {
        car[x][0]=dc[x];
        car[x][1]=l;
    }
    int t=ceil(v-vc[x])/ac[x];
    if(t<0)
    {
        car[x][0]=-1;
        car[x][0]=-1;
        return ;
    }
    int s=int((v*v-vc[x]*vc[x])/2/ac[x]);
   // cout<<x<<" "<<s<<endl;
    if(ac[x]>0)
    {
        car[x][0]=dc[x]+s;
        car[x][1]=l;
    }
    else if(ac[x]<0)
    {
        car[x][0]=dc[x];
        car[x][1]=dc[x]+s;
    }
}
bool cmp(vector<int> a,vector <int> b)
{
    int alen=0,blen=0;
    for(int i=0;i<a.size();i++) if(!f[i])alen++;
    for(int i=0;i<b.size();i++) if(!f[i])blen++;
    if(alen>blen)return a>b;
    else return b>a;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>l>>v;
        memset(dc,0,sizeof(dc));
        memset(vc,0,sizeof(vc));
        memset(ac,0,sizeof(ac));
        memset(p,0,sizeof(p));
        memset(f,0,sizeof(f));
        vector<int> s[100005];
        for(int i=1;i<=n;i++)cin>>dc[i]>>vc[i]>>ac[i];
        for(int i=1;i<=m;i++)cin>>p[i];
        sort(p+1,p+1+m);
        for(int i=1;i<=n;i++)check(i);
        for(int i=1;i<=n;i++)
        {
            if(car[i][0]==-1&&car[i][1]==-1)continue;
            for(int j=1;j<=m;j++)
            {
                if(car[i][0]<=p[j]&&p[j]<=car[i][1])
                {
                    //cout<<i<<endl;
                    ans1++;
                    break;
                }
            }
        }
        cout<<ans1<<" ";
        for(int i=1;i<=n;i++)
        {
            if(car[i][0]==-1&&car[i][1]==-1)continue;
            for(int j=1;j<=m;j++)
            {
                if(car[i][0]<=p[j]&&p[j]<=car[i][1])
                {
                    s[j].push_back(i);
                }
            }
        }
        sort(s,s+m,cmp);/*
        for(int i=1;i<=n;i++)
        {
            bool g=false;
            for(int i=1;i<=n;i++)
            {
                if(!f[i])g=true;
            }
            if(!g){break;}
            ans2++;
            for(int j=0;j<s[i].size();j++)
            {
                f[s[i][j]]=true;
            }
            sort(s,s+m,cmp);
        }*/
        int w=0,i=0;
        while(w<n)
        {
            w+=s[i].size();
            i++;
        }
        ans2=i+1;
        cout<<ans2;
        /*for(int i=1;i<=n;i++)
        {
            cout<<car[i][0]<<" "<<car[i][1]<<endl;
        }*/
    }
    return 0;
}
